package com.itgungnir.designpattern.interpreter;

public class MultiplyExpression extends Expression {
	private String resultExpressionKey;
	private Expression leftExpression;
	private Expression rightExpression;

	public MultiplyExpression(String resultExpressionKey, Expression leftExpression, Expression rightExpression) {
		this.resultExpressionKey = resultExpressionKey;
		this.leftExpression = leftExpression;
		this.rightExpression = rightExpression;
	}

	@Override
	public Expression interpret(Context context) {
		Integer rightVariableValue = ((VariableExpression) rightExpression).getValue();
		return new VariableExpression(resultExpressionKey,
				((VariableExpression) leftExpression).getValue() * rightVariableValue);
	}
}